package com.example.myapplication.tack_15;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.example.myapplication.R;
import com.example.myapplication.tack_15.adapter.ArrangeAdapter;
import com.example.myapplication.tack_15.adapter.WoDeAdapter;
import com.example.myapplication.tack_15.data.ArrangeData;
import com.example.myapplication.tack_15.data.WoDeData;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class WoDeActivity extends AppCompatActivity {
    private ImageView exit;
    private List<WoDeData.RowsDTO> listWoDe;
    private RecyclerView arrange;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_15_activity_wo_de);
        init();
        exit_();
        getArrange();
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WoDeActivity.this.finish();
            }
        });
    }
    private void getArrange() {
        String url = "prod-api/api/lawyer-consultation/legal-advice/list";
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, WoDeData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                WoDeData woDeData = (WoDeData)obj;
                if(woDeData.getCode() == 200){
                    listWoDe = woDeData.getRows();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            wodeAdapter();
                        }
                    });
                }
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void wodeAdapter() {
        WoDeAdapter woDeAdapter = new WoDeAdapter(listWoDe, WoDeActivity.this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(WoDeActivity.this);
        arrange.setLayoutManager(linearLayoutManager);
        arrange.setAdapter(woDeAdapter);
    }

    private void init() {
        exit = findViewById(R.id.exit);
        arrange = findViewById(R.id.arrange);
    }

}